package com.aigc.sclassroom.mapper;

import com.aigc.sclassroom.pojo.Survey;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SurveyMapper{
    @Insert("insert into survey(survey_name,course_manage_id,create_time)" +
            "values (#{surveyName},#{courseManageId},now())")
    void add( String surveyName,  Long courseManageId);


    //根据课程id查询该课程所有问卷
    @Select("select s.survey_id,s.survey_name,s.course_manage_id,s.create_time\n" +
            "from survey s\n" +
            "left join course_manage cm on cm.course_manage_id = s.course_manage_id\n" +
            "where s.course_manage_id=#{courseManageId};")
    List<Survey> selectSurveyByCourseManageId(Long courseManageId);


    //查询该课程学生人数
    @Select("select count(team_id)\n" +
            "from team t\n" +
            "left join course_manage cm on t.course_manage_id = cm.course_manage_id\n" +
            "where t.course_manage_id=#{courseManageId}")
    Long selectSum(Long courseManageId);

    //查询某课节反馈表提交人数
    @Select("select count(feedback_id)\n" +
            "from feedback f\n" +
            "left join survey s on f.survey_id=s.survey_id\n" +
            "where f.survey_id=#{surveyId} and s.course_manage_id=#{courseManageId}")
    Long selectSubmitCount(Long surveyId,Long courseManageId);

    @Select("select s.course_manage_id\n" +
            "from survey s\n" +
            "left join course_manage cm on s.course_manage_id = cm.course_manage_id\n" +
            "where survey_id = #{surveyId}")
    Long selectCourseManageIdBysurveyId(Long surveyId);
}
